package com.sfpay.coreplatform.order.service.composite.impl;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.annotation.Resource;

import com.sfpay.coreplatform.order.common.enums.TradeType;
import com.sfpay.coreplatform.order.common.enums.tradeStatus;
import com.sfpay.coreplatform.order.persistence.dao.IPayOrderDao;
import com.sfpay.coreplatform.order.persistence.dao.ITradeOrderDao;
import com.sfpay.coreplatform.order.service.composite.IHandler;
import com.sfpay.coreplatform.order.service.composite.QueryOrderService;
import com.sfpay.coreplatform.order.service.composite.common.PayContext;
import com.sfpay.coreplatform.order.service.exception.OrderServiceException;
import com.sfpay.coreplatform.order.service.proxy.account.IAccountMgrProxyService;
import com.sfpay.coreplatform.order.valueobject.dto.PayRequest;
import com.sfpay.coreplatform.order.valueobject.dto.Response;
import com.sfpay.coreplatform.order.valueobject.tmo.TradeOrder;

public abstract class AbstractHandler implements IHandler {

	@Resource
	private ITradeOrderDao tradeOrderDao;

	@Resource
	private IPayOrderDao payOrderDao;

	@Resource
	private IAccountMgrProxyService accountService;
	
	@Resource
	protected QueryOrderService queryOrderService;

	// 存储进行的外部订单号
	protected static final Map<String, String> codeMap = new ConcurrentHashMap<String, String>();

	public ITradeOrderDao getTradeOrderDao() {
		return tradeOrderDao;
	}

	public IPayOrderDao getPayOrderDao() {
		return payOrderDao;
	}

	public IAccountMgrProxyService getAccountService() {
		return accountService;
	}
	/**
	 * 查询交易状态
	 * @param trades
	 * @param tradeType
	 * @return
	 */
	public tradeStatus getTradeStatus(List<TradeOrder> trades,
			TradeType tradeType) {

		if (trades != null) {
			for (TradeOrder tradeOrder : trades) {
				if (tradeType == tradeOrder.getTradeType()) {

					return tradeOrder.getOrderStatus();
				}
			}
		}
		return null;
	}

}
